package com.isoftstone.app.controller.city;

import com.isoftstone.bank.controller.base.BaseController;
import com.isoftstone.common.Tidings;
import com.isoftstone.merchant.entity.city.City;
import com.isoftstone.merchant.entity.merchant.Merchant;
import com.isoftstone.merchant.service.city.impl.CityServiceImpl;
import com.isoftstone.merchant.service.merchant.impl.MerchantServiceImpl;
import com.isoftstone.util.Const;
import com.isoftstone.util.PropertiesUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @Author: zhaojg
 * @Description
 * @Date: Created in 9:07 2017/12/6
 * @Modified by:
 *
 * 查询缴费地区接口
 */

@Controller
public class PaymentCity extends BaseController {

    @Autowired
    CityServiceImpl cityService;

    @Autowired
    MerchantServiceImpl merchantService;
    /**
     * 查询山东省的缴费地区
     */
    @RequestMapping(value = "app/admin/QueryCity",method = RequestMethod.POST)
    @ResponseBody
    public Tidings<Map<String, Object>> getPaymentCity() {
        Tidings<Map<String, Object>> tidings = new Tidings<Map<String, Object>>();
        ArrayList<String> strArray = new ArrayList<String> ();
        try {
            Map<String, Object> reMap = new HashMap<String, Object>();
            List<City> paymentCityList = cityService.getPaymentCityList();
            //创建一个字符串数组
            for (City city : paymentCityList) {
                strArray.add(city.getCityName());
            }
            reMap.put("paymentCityList",paymentCityList);
            tidings.setMsg("成功");
            tidings.setStatus(Const.SUCCESS);
            tidings.setT(reMap);
        } catch (Exception e) {
            tidings.setMsg("失败");
            tidings.setStatus(Const.ERROR);
            e.printStackTrace();
        }
        return tidings;
    }

    /**
     * 查询指定缴费地区下的缴费单位
     */
    @RequestMapping(value = "app/admin/QueryFeeUnitByCity",method = RequestMethod.POST)
    @ResponseBody
    public Tidings<Map<String, Object>> getPaymentProject(String cityId) {
        Tidings<Map<String, Object>> tidings = new Tidings<Map<String, Object>>();
        Map<String, Object> reMap = new HashMap<String, Object>();
        List<Merchant> merchantList = null;
        try {
            merchantList = merchantService.getMerchantBycityId(cityId);
            for (Merchant merchant : merchantList) {
                String cityId1 = merchant.getCityId();
                if(cityId1 == null){
                    merchantList = null;
                }
                String logoFile = merchant.getLogoFile();
                if (logoFile != null) {
                    String path = PropertiesUtils.getProperties("baseContextPath") + Const.FILEPATHIMG + logoFile;
                    merchant.setLogoFile(path);
                }
            }
            reMap.put("merchantList",merchantList);
            tidings.setMsg("成功");
            tidings.setStatus(Const.SUCCESS);
            tidings.setT(reMap);
        } catch (Exception e) {
            tidings.setMsg("失败");
            tidings.setStatus(Const.ERROR);
            e.printStackTrace();
        }
        return tidings;
    }



}
